package cn.itsource.quartz.service.impl;

import cn.itsource.quartz.domain.QuartzJobInfo;
import cn.itsource.quartz.job.MainJob;
import cn.itsource.quartz.service.IQuartZService;
import cn.itsource.quartz.utils.QuartzUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

import javax.xml.validation.SchemaFactory;

@Service
public class QuartZServiceImpl implements IQuartZService {

    @Autowired
    private SchedulerFactoryBean factoryBean;

    //Scheduler sched, String jobName, @SuppressWarnings("rawtypes") Class cls, Object params,
    //         String time
    @Override
    public void addJob(QuartzJobInfo quartzJobInfo) {
        QuartzUtils.addJob(factoryBean.getScheduler(), quartzJobInfo.getJobName(), MainJob.class, quartzJobInfo.getParams(), quartzJobInfo.getCronj());

    }

    @Override
    public void removeJob(String jobName) {
        QuartzUtils.removeJob(factoryBean.getScheduler(), jobName);
    }
}
